<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>git常用命令大全 | 博客</title><meta name="keywords" content="git"><meta name="author" content="小魂"><meta name="copyright" content="小魂"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Git命令大全 git config  123456789101112131415161718192021222324252627282930313233343536373839404142# 查看配置信息# --local：仓库级，--global：全局级，--system：系统级$ git config &lt;--local | --global | --system&gt; -l# 查看当">
<meta property="og:type" content="article">
<meta property="og:title" content="git常用命令大全">
<meta property="og:url" content="https://shark-yun.gitee.io/blog/2020/06/15/git%E6%95%99%E7%A8%8B/git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E5%A4%A7%E5%85%A8/index.html">
<meta property="og:site_name" content="博客">
<meta property="og:description" content="Git命令大全 git config  123456789101112131415161718192021222324252627282930313233343536373839404142# 查看配置信息# --local：仓库级，--global：全局级，--system：系统级$ git config &lt;--local | --global | --system&gt; -l# 查看当">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://shark-yun.gitee.io/blog/img/orcal%E6%95%B0%E6%8D%AE%E5%BA%93%E6%97%B6%E9%97%B4%E8%AE%BE%E7%BD%AE%E9%97%AE%E9%A2%98/index.jpg">
<meta property="article:published_time" content="2020-06-15T13:15:50.000Z">
<meta property="article:modified_time" content="2021-02-27T10:04:17.554Z">
<meta property="article:author" content="小魂">
<meta property="article:tag" content="git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://shark-yun.gitee.io/blog/img/orcal%E6%95%B0%E6%8D%AE%E5%BA%93%E6%97%B6%E9%97%B4%E8%AE%BE%E7%BD%AE%E9%97%AE%E9%A2%98/index.jpg"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://shark-yun.gitee.io/blog/2020/06/15/git%E6%95%99%E7%A8%8B/git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E5%A4%A7%E5%85%A8/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-02-27 18:04:17'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"> <script src="/blog/live2d-widget/autoload.js"></script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/blog/img/style/touxiang.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">26</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">14</div></a></div></div></div><hr/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/blog/img/orcal%E6%95%B0%E6%8D%AE%E5%BA%93%E6%97%B6%E9%97%B4%E8%AE%BE%E7%BD%AE%E9%97%AE%E9%A2%98/index.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">博客</a></span><div id="menus"><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">git常用命令大全</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-06-15T13:15:50.000Z" title="发表于 2020-06-15 21:15:50">2020-06-15</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-02-27T10:04:17.554Z" title="更新于 2021-02-27 18:04:17">2021-02-27</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="Git命令大全"><a href="#Git命令大全" class="headerlink" title="Git命令大全"></a>Git命令大全</h3><blockquote>
<p>git config</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"># 查看配置信息</span><br><span class="line"># --local：仓库级，--global：全局级，--system：系统级</span><br><span class="line">$ git config &lt;--local | --global | --system&gt; -l</span><br><span class="line"></span><br><span class="line"># 查看当前生效的配置信息</span><br><span class="line">$ git config -l</span><br><span class="line"></span><br><span class="line"># 编辑配置文件</span><br><span class="line"># --local：仓库级，--global：全局级，--system：系统级</span><br><span class="line">$ git config &lt;--local | --global | --system&gt; -e</span><br><span class="line"></span><br><span class="line"># 添加配置项</span><br><span class="line"># --local：仓库级，--global：全局级，--system：系统级</span><br><span class="line">$ git config &lt;--local | --global | --system&gt; --add &lt;name&gt; &lt;value&gt;</span><br><span class="line"></span><br><span class="line"># 获取配置项</span><br><span class="line">$ git config &lt;--local | --global | --system&gt; --get &lt;name&gt;</span><br><span class="line"></span><br><span class="line"># 删除配置项</span><br><span class="line">$ git config &lt;--local | --global | --system&gt; --unset &lt;name&gt;</span><br><span class="line"></span><br><span class="line"># 配置提交记录中的用户信息</span><br><span class="line">$ git config --global user.name &lt;用户名&gt;</span><br><span class="line">$ git config --global user.email &lt;邮箱地址&gt;</span><br><span class="line"></span><br><span class="line"># 更改Git缓存区的大小</span><br><span class="line"># 如果提交的内容较大，默认缓存较小，提交会失败</span><br><span class="line"># 缓存大小单位：B，例如：524288000（500MB）</span><br><span class="line">$ git config --global http.postBuffer &lt;缓存大小&gt;</span><br><span class="line"></span><br><span class="line"># 调用 git status&#x2F;git diff 命令时以高亮或彩色方式显示改动状态</span><br><span class="line">$ git config --global color.ui true</span><br><span class="line"></span><br><span class="line"># 配置可以缓存密码，默认缓存时间15分钟</span><br><span class="line">$ git config --global credential.helper cache</span><br><span class="line"></span><br><span class="line"># 配置密码的缓存时间</span><br><span class="line"># 缓存时间单位：秒</span><br><span class="line">$ git config --global credential.helper &#39;cache --timeout&#x3D;&lt;缓存时间&gt;&#39;</span><br><span class="line"></span><br><span class="line"># 配置长期存储密码</span><br><span class="line">$ git config --global credential.helper store</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git clone</p>
</blockquote>
<p>从远程仓库克隆一个版本库到本地。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># 默认在当前目录下创建和版本库名相同的文件夹并下载版本到该文件夹下</span><br><span class="line">$ git clone &lt;远程仓库的网址&gt;</span><br><span class="line"></span><br><span class="line"># 指定本地仓库的目录</span><br><span class="line">$ git clone &lt;远程仓库的网址&gt; &lt;本地目录&gt;</span><br><span class="line"></span><br><span class="line"># -b 指定要克隆的分支，默认是master分支</span><br><span class="line">$ git clone &lt;远程仓库的网址&gt; -b &lt;分支名称&gt; &lt;本地目录&gt;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>git init</p>
</blockquote>
<p>初始化项目所在目录，初始化后会在当前目录下出现一个名为 .git 的目录。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 初始化本地仓库，在当前目录下生成 .git 文件夹</span><br><span class="line">$ git init</span><br></pre></td></tr></table></figure>
<blockquote>
<p>git status</p>
</blockquote>
<p>查看本地仓库的状态。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"># 查看本地仓库的状态</span><br><span class="line">$ git status</span><br><span class="line"></span><br><span class="line"># 以简短模式查看本地仓库的状态</span><br><span class="line"># 会显示两列，第一列是文件的状态，第二列是对应的文件</span><br><span class="line"># 文件状态：A 新增，M 修改，D 删除，?? 未添加到Git中</span><br><span class="line">$ git status -s</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git remote</p>
</blockquote>
<p>操作远程库。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"># 列出已经存在的远程仓库</span><br><span class="line">$ git remote</span><br><span class="line"></span><br><span class="line"># 列出远程仓库的详细信息，在别名后面列出URL地址</span><br><span class="line">$ git remote -v</span><br><span class="line">$ git remote --verbose</span><br><span class="line"></span><br><span class="line"># 添加远程仓库</span><br><span class="line">$ git remote add &lt;远程仓库的别名&gt; &lt;远程仓库的URL地址&gt;</span><br><span class="line"></span><br><span class="line"># 修改远程仓库的别名</span><br><span class="line">$ git remote rename &lt;原远程仓库的别名&gt; &lt;新的别名&gt;</span><br><span class="line"></span><br><span class="line"># 删除指定名称的远程仓库</span><br><span class="line">$ git remote remove &lt;远程仓库的别名&gt;</span><br><span class="line"></span><br><span class="line"># 修改远程仓库的 URL 地址</span><br><span class="line">$ git remote set-url &lt;远程仓库的别名&gt; &lt;新的远程仓库URL地址&gt;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git branch</p>
</blockquote>
<p>操作 Git 的分支命令。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"># 列出本地的所有分支，当前所在分支以 &quot;*&quot; 标出</span><br><span class="line">$ git branch</span><br><span class="line"></span><br><span class="line"># 列出本地的所有分支并显示最后一次提交，当前所在分支以 &quot;*&quot; 标出</span><br><span class="line">$ git branch -v</span><br><span class="line"></span><br><span class="line"># 创建新分支，新的分支基于上一次提交建立</span><br><span class="line">$ git branch &lt;分支名&gt;</span><br><span class="line"></span><br><span class="line"># 修改分支名称</span><br><span class="line"># 如果不指定原分支名称则为当前所在分支</span><br><span class="line">$ git branch -m [&lt;原分支名称&gt;] &lt;新的分支名称&gt;</span><br><span class="line"># 强制修改分支名称</span><br><span class="line">$ git branch -M [&lt;原分支名称&gt;] &lt;新的分支名称&gt;</span><br><span class="line"></span><br><span class="line"># 删除指定的本地分支</span><br><span class="line">$ git branch -d &lt;分支名称&gt;</span><br><span class="line"></span><br><span class="line"># 强制删除指定的本地分支</span><br><span class="line">$ git branch -D &lt;分支名称&gt;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git checkout</p>
</blockquote>
<p>检出命令，用于创建、切换分支等。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># 切换到已存在的指定分支</span><br><span class="line">$ git checkout &lt;分支名称&gt;</span><br><span class="line"></span><br><span class="line"># 创建并切换到指定的分支，保留所有的提交记录</span><br><span class="line"># 等同于 &quot;git branch&quot; 和 &quot;git checkout&quot; 两个命令合并</span><br><span class="line">$ git checkout -b &lt;分支名称&gt;</span><br><span class="line"></span><br><span class="line"># 创建并切换到指定的分支，删除所有的提交记录</span><br><span class="line">$ git checkout --orphan &lt;分支名称&gt;</span><br><span class="line"></span><br><span class="line"># 替换掉本地的改动，新增的文件和已经添加到暂存区的内容不受影响</span><br><span class="line">$ git checkout &lt;文件路径&gt;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git cherry-pick</p>
</blockquote>
<p>把已经提交的记录合并到当前分支。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 把已经提交的记录合并到当前分支</span><br><span class="line">$ git cherry-pick &lt;commit ID&gt;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git add</p>
</blockquote>
<p>把要提交的文件的信息添加到暂存区中。当使用 git commit 时，将依据暂存区中的内容来进行文件的提交。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># 把指定的文件添加到暂存区中</span><br><span class="line">$ git add &lt;文件路径&gt;</span><br><span class="line"></span><br><span class="line"># 添加所有修改、已删除的文件到暂存区中</span><br><span class="line">$ git add -u [&lt;文件路径&gt;]</span><br><span class="line">$ git add --update [&lt;文件路径&gt;]</span><br><span class="line"></span><br><span class="line"># 添加所有修改、已删除、新增的文件到暂存区中，省略 &lt;文件路径&gt; 即为当前目录</span><br><span class="line">$ git add -A [&lt;文件路径&gt;]</span><br><span class="line">$ git add --all [&lt;文件路径&gt;]</span><br><span class="line"></span><br><span class="line"># 查看所有修改、已删除但没有提交的文件，进入一个子命令系统</span><br><span class="line">$ git add -i [&lt;文件路径&gt;]</span><br><span class="line">$ git add --interactive [&lt;文件路径&gt;]</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git commit</p>
</blockquote>
<p>将暂存区中的文件提交到本地仓库中。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># 把暂存区中的文件提交到本地仓库，调用文本编辑器输入该次提交的描述信息</span><br><span class="line">$ git commit</span><br><span class="line"></span><br><span class="line"># 把暂存区中的文件提交到本地仓库中并添加描述信息</span><br><span class="line">$ git commit -m &quot;&lt;提交的描述信息&gt;&quot;</span><br><span class="line"></span><br><span class="line"># 把所有修改、已删除的文件提交到本地仓库中</span><br><span class="line"># 不包括未被版本库跟踪的文件，等同于先调用了 &quot;git add -u&quot;</span><br><span class="line">$ git commit -a -m &quot;&lt;提交的描述信息&gt;&quot;</span><br><span class="line"></span><br><span class="line"># 修改上次提交的描述信息</span><br><span class="line">$ git commit --amend</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git fetch</p>
</blockquote>
<p>从远程仓库获取最新的版本到本地的 tmp 分支上。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 将远程仓库所有分支的最新版本全部取回到本地</span><br><span class="line">$ git fetch &lt;远程仓库的别名&gt;</span><br><span class="line"></span><br><span class="line"># 将远程仓库指定分支的最新版本取回到本地</span><br><span class="line">$ git fetch &lt;远程主机名&gt; &lt;分支名&gt;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git merge</p>
</blockquote>
<p>合并分支。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 把指定的分支合并到当前所在的分支下</span><br><span class="line">$ git merge &lt;分支名称&gt;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git diff</p>
</blockquote>
<p>比较版本之间的差异。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"># 比较当前文件和暂存区中文件的差异，显示没有暂存起来的更改</span><br><span class="line">$ git diff</span><br><span class="line"></span><br><span class="line"># 比较暂存区中的文件和上次提交时的差异</span><br><span class="line">$ git diff --cached</span><br><span class="line">$ git diff --staged</span><br><span class="line"></span><br><span class="line"># 比较当前文件和上次提交时的差异</span><br><span class="line">$ git diff HEAD</span><br><span class="line"></span><br><span class="line"># 查看从指定的版本之后改动的内容</span><br><span class="line">$ git diff &lt;commit ID&gt;</span><br><span class="line"></span><br><span class="line"># 比较两个分支之间的差异</span><br><span class="line">$ git diff &lt;分支名称&gt; &lt;分支名称&gt;</span><br><span class="line"></span><br><span class="line"># 查看两个分支分开后各自的改动内容</span><br><span class="line">$ git diff &lt;分支名称&gt;...&lt;分支名称&gt;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>git pull</p>
</blockquote>
<p>从远程仓库获取最新版本并合并到本地。<br>首先会执行 git fetch，然后执行 git merge，把获取的分支的 HEAD 合并到当前分支。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># 从远程仓库获取最新版本。</span><br><span class="line">$ git pull</span><br><span class="line"></span><br><span class="line">git push</span><br><span class="line">把本地仓库的提交推送到远程仓库。</span><br><span class="line"></span><br><span class="line"># 把本地仓库的分支推送到远程仓库的指定分支</span><br><span class="line">$ git push &lt;远程仓库的别名&gt; &lt;本地分支名&gt;:&lt;远程分支名&gt;</span><br><span class="line"></span><br><span class="line"># 删除指定的远程仓库的分支</span><br><span class="line">$ git push &lt;远程仓库的别名&gt; :&lt;远程分支名&gt;</span><br><span class="line">$ git push &lt;远程仓库的别名&gt; --delete &lt;远程分支名&gt;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git log</p>
</blockquote>
<p>显示提交的记录。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"># 打印所有的提交记录</span><br><span class="line">$ git log</span><br><span class="line"></span><br><span class="line"># 打印从第一次提交到指定的提交的记录</span><br><span class="line">$ git log &lt;commit ID&gt;</span><br><span class="line"></span><br><span class="line"># 打印指定数量的最新提交的记录</span><br><span class="line">$ git log -&lt;指定的数量&gt;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git reset</p>
</blockquote>
<p>还原提交记录。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"># 重置暂存区，但文件不受影响</span><br><span class="line"># 相当于将用 &quot;git add&quot; 命令更新到暂存区的内容撤出暂存区，可以指定文件</span><br><span class="line"># 没有指定 commit ID 则默认为当前 HEAD</span><br><span class="line">$ git reset [&lt;文件路径&gt;]</span><br><span class="line">$ git reset --mixed [&lt;文件路径&gt;]</span><br><span class="line"></span><br><span class="line"># 将 HEAD 的指向改变，撤销到指定的提交记录，文件未修改</span><br><span class="line">$ git reset &lt;commit ID&gt;</span><br><span class="line">$ git reset --mixed &lt;commit ID&gt;</span><br><span class="line"></span><br><span class="line"># 将 HEAD 的指向改变，撤销到指定的提交记录，文件未修改</span><br><span class="line"># 相当于调用 &quot;git reset --mixed&quot; 命令后又做了一次 &quot;git add&quot;</span><br><span class="line">$ git reset --soft &lt;commit ID&gt;</span><br><span class="line"></span><br><span class="line"># 将 HEAD 的指向改变，撤销到指定的提交记录，文件也修改了</span><br><span class="line">$ git reset --hard &lt;commit ID&gt;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git revert</p>
</blockquote>
<p>生成一个新的提交来撤销某次提交，此次提交之前的所有提交都会被保留。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"># 生成一个新的提交来撤销某次提交</span><br><span class="line">$ git revert &lt;commit ID&gt;</span><br><span class="line"></span><br><span class="line">git tag</span><br><span class="line">操作标签的命令。</span><br><span class="line"></span><br><span class="line"># 打印所有的标签</span><br><span class="line">$ git tag</span><br><span class="line"></span><br><span class="line"># 添加轻量标签，指向提交对象的引用，可以指定之前的提交记录</span><br><span class="line">$ git tag &lt;标签名称&gt; [&lt;commit ID&gt;]</span><br><span class="line"></span><br><span class="line"># 添加带有描述信息的附注标签，可以指定之前的提交记录</span><br><span class="line">$ git tag -a &lt;标签名称&gt; -m &lt;标签描述信息&gt; [&lt;commit ID&gt;]</span><br><span class="line"></span><br><span class="line"># 切换到指定的标签</span><br><span class="line">$ git checkout &lt;标签名称&gt;</span><br><span class="line"></span><br><span class="line"># 查看标签的信息</span><br><span class="line">$ git show &lt;标签名称&gt;</span><br><span class="line"></span><br><span class="line"># 删除指定的标签</span><br><span class="line">$ git tag -d &lt;标签名称&gt;</span><br><span class="line"></span><br><span class="line"># 将指定的标签提交到远程仓库</span><br><span class="line">$ git push &lt;远程仓库的别名&gt; &lt;标签名称&gt;</span><br><span class="line"></span><br><span class="line"># 将本地所有的标签全部提交到远程仓库</span><br><span class="line">$ git push &lt;远程仓库的别名&gt; –tags</span><br></pre></td></tr></table></figure>

<blockquote>
<p>git mv</p>
</blockquote>
<p>重命名文件或者文件夹。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"># 重命名指定的文件或者文件夹</span><br><span class="line">$ git mv &lt;源文件&#x2F;文件夹&gt; &lt;目标文件&#x2F;文件夹&gt;</span><br><span class="line"></span><br><span class="line">git rm</span><br><span class="line">删除文件或者文件夹。</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"># 移除跟踪指定的文件，并从本地仓库的文件夹中删除</span><br><span class="line">$ git rm &lt;文件路径&gt;</span><br><span class="line"></span><br><span class="line"># 移除跟踪指定的文件夹，并从本地仓库的文件夹中删除</span><br><span class="line">$ git rm -r &lt;文件夹路径&gt;</span><br><span class="line"></span><br><span class="line"># 移除跟踪指定的文件，在本地仓库的文件夹中保留该文件</span><br><span class="line">$ git rm --cached</span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">小魂</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://shark-yun.gitee.io/blog/2020/06/15/git%E6%95%99%E7%A8%8B/git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E5%A4%A7%E5%85%A8/">https://shark-yun.gitee.io/blog/2020/06/15/git%E6%95%99%E7%A8%8B/git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E5%A4%A7%E5%85%A8/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://shark-yun.gitee.io/blog" target="_blank">博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/git/">git</a></div><div class="post_share"><div class="social-share" data-image="/blog/img/orcal%E6%95%B0%E6%8D%AE%E5%BA%93%E6%97%B6%E9%97%B4%E8%AE%BE%E7%BD%AE%E9%97%AE%E9%A2%98/index.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/blog/" target="_blank"><img class="post-qr-code-img" src="/blog/"/></a><div class="post-qr-code-desc"></div></li><li class="reward-item"><a href="/blog/" target="_blank"><img class="post-qr-code-img" src="/blog/"/></a><div class="post-qr-code-desc"></div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2020/06/17/git%E6%95%99%E7%A8%8B/git%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/"><img class="prev-cover" src="/blog/img/%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%90%E7%BB%B4/python3/theme.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">git的基本使用</div></div></a></div><div class="next-post pull-right"><a href="/blog/2020/06/09/%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E5%86%99%E5%87%BApython%E4%BB%A3%E7%A0%81/%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E5%86%99%E5%87%BApython%E4%BB%A3%E7%A0%81/"><img class="next-cover" src="/blog/img/%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E5%86%99%E5%87%BApython%E4%BB%A3%E7%A0%81/%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E5%86%99%E5%87%BApython%E4%BB%A3%E7%A0%81/index.png" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">如何优雅的写出python代码</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2020/06/17/git教程/git的基本使用/" title="git的基本使用"><img class="cover" src="/blog/img/%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%90%E7%BB%B4/python3/theme.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-06-17</div><div class="title">git的基本使用</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="/blog/img/style/touxiang.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">小魂</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">26</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">14</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/shangxiaohun/dashboard/projects" target="_blank" title="Github"><i class="fa fa-github"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#Git%E5%91%BD%E4%BB%A4%E5%A4%A7%E5%85%A8"><span class="toc-number">1.</span> <span class="toc-text">Git命令大全</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/04/21/%E6%98%BE%E7%A4%BA%E5%99%A8/xianshiqi/" title="Linux开启显示器内置声卡"><img src="/blog/img/%E6%98%BE%E7%A4%BA%E5%99%A8/picture/index.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="Linux开启显示器内置声卡"/></a><div class="content"><a class="title" href="/blog/2021/04/21/%E6%98%BE%E7%A4%BA%E5%99%A8/xianshiqi/" title="Linux开启显示器内置声卡">Linux开启显示器内置声卡</a><time datetime="2021-04-21T05:08:50.000Z" title="发表于 2021-04-21 13:08:50">2021-04-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/02/09/%E6%95%99%E7%A8%8B/%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87/" title="环境准备"><img src="/blog/img/%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E5%86%99%E5%87%BApython%E4%BB%A3%E7%A0%81/%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E5%86%99%E5%87%BApython%E4%BB%A3%E7%A0%81/index.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="环境准备"/></a><div class="content"><a class="title" href="/blog/2021/02/09/%E6%95%99%E7%A8%8B/%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87/" title="环境准备">环境准备</a><time datetime="2021-02-09T02:59:50.000Z" title="发表于 2021-02-09 10:59:50">2021-02-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2021/02/07/%E6%95%99%E7%A8%8B/%E5%88%86%E6%9E%90%E5%BB%BA%E5%BA%93%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C/" title="分析建库准备工作"><img src="/blog/img/%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E5%86%99%E5%87%BApython%E4%BB%A3%E7%A0%81/%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E5%86%99%E5%87%BApython%E4%BB%A3%E7%A0%81/index.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="分析建库准备工作"/></a><div class="content"><a class="title" href="/blog/2021/02/07/%E6%95%99%E7%A8%8B/%E5%88%86%E6%9E%90%E5%BB%BA%E5%BA%93%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C/" title="分析建库准备工作">分析建库准备工作</a><time datetime="2021-02-07T08:15:50.000Z" title="发表于 2021-02-07 16:15:50">2021-02-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2020/09/27/%E9%80%81%E7%BB%99%E5%B0%8F%E5%AD%A6%E5%BC%9F%E7%9A%84%E4%B8%80%E5%B0%81%E4%BF%A1/%E9%80%81%E7%BB%99%E5%B0%8F%E5%AD%A6%E5%BC%9F%E7%9A%84%E4%B8%80%E5%B0%81%E4%BF%A1/" title="送给小学弟的一封信"><img src="/blog/img/%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E5%86%99%E5%87%BApython%E4%BB%A3%E7%A0%81/%E5%A6%82%E4%BD%95%E4%BC%98%E9%9B%85%E7%9A%84%E5%86%99%E5%87%BApython%E4%BB%A3%E7%A0%81/index.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="送给小学弟的一封信"/></a><div class="content"><a class="title" href="/blog/2020/09/27/%E9%80%81%E7%BB%99%E5%B0%8F%E5%AD%A6%E5%BC%9F%E7%9A%84%E4%B8%80%E5%B0%81%E4%BF%A1/%E9%80%81%E7%BB%99%E5%B0%8F%E5%AD%A6%E5%BC%9F%E7%9A%84%E4%B8%80%E5%B0%81%E4%BF%A1/" title="送给小学弟的一封信">送给小学弟的一封信</a><time datetime="2020-09-26T18:20:50.000Z" title="发表于 2020-09-27 02:20:50">2020-09-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2020/07/11/%E5%82%85%E7%AB%8B%E5%8F%B6%E5%8F%98%E6%8D%A2/%E5%82%85%E7%AB%8B%E5%8F%B6%E5%8F%98%E6%8D%A2/" title="傅立叶变换"><img src="/blog/img/opencv/opencv_split_img/opencv_split_img_style.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="傅立叶变换"/></a><div class="content"><a class="title" href="/blog/2020/07/11/%E5%82%85%E7%AB%8B%E5%8F%B6%E5%8F%98%E6%8D%A2/%E5%82%85%E7%AB%8B%E5%8F%B6%E5%8F%98%E6%8D%A2/" title="傅立叶变换">傅立叶变换</a><time datetime="2020-07-11T15:53:50.000Z" title="发表于 2020-07-11 23:53:50">2020-07-11</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By 小魂</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">你只管努力，剩下的交给时间</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>